package com.kuanter.kuanterauto.entity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.kuanter.kuanterauto.utils.StringUtils;
/**
 * 消费记录数据
 * @author soup
 *
 */
public class ConsumptionList {

	// {"consumptionList":
	// [{"consumptionAmount":"15","consumptionCard":"11001261","consumptionShop":"文生汽车音响装饰城","consumptionTime":"2012-10-31 07:53:58",
	// "consumptionType":"小型车清洗","id":319564},],"status":true}
	public static String TAG = "ConsumptionList";

	private List<Consumption> consumptions = null;

	public ConsumptionList(String json) {
		System.out.println(json);
		try {
			JSONObject jobj = new JSONObject(json);
			if (StringUtils.isSuccess(json)) {
				JSONArray jarr = jobj.optJSONArray("consumptionList");
				if (jarr != null && jarr.length() > 0) {
					consumptions = new ArrayList<Consumption>();
					for (int i = 0; i < jarr.length(); i++) {
						JSONObject jo = jarr.optJSONObject(i);
						Consumption consumption = new Consumption();
						consumption.setConsumptionAmount(jo
								.optString("consumptionAmount"));
						consumption.setConsumptionCard(jo
								.optString("consumptionCard"));
						consumption.setConsumptionShop(jo
								.optString("consumptionShop"));
						consumption.setConsumptionTime(jo
								.optString("consumptionTime"));
						consumption.setConsumptionType(jo
								.optString("consumptionType"));
						consumption.setId(jo.optString("id"));
						consumptions.add(consumption);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<Consumption> getConsumptionList() {
		return consumptions;
	}

}
